# 作业2-1
class Student(object):
    count = 0
    def __init__(self, name):
        self.name = name
        Student.count += 1

xiaoming = Student('xiaoming')
print('学生人数为:', Student.count)

# 作业2-2

import functools
import time
from math import sin


def metric(fn):
    @functools.wraps(fn)
    def wrapper(*args, **kw):
        start_time = time.time()
        print('函数执行开始时间:', time.time())
        r = fn(*args, **kw)           # r指向被metric装饰的函数，确定目标函数已执行
        end_time = time.time()
        print('函数执行结束时间:', end_time)
        print('%s 执行时间为: %s ms' % (fn.__name__, (time.time()- start_time)))
        return r
    return wrapper
@metric
def f(x, y):
    sum = 0
    for i in range(x):
        sum += sin(i) + i * i + y * i
    print('f函数的执行结果为:', sum)

# 测试
f(4, 5)


